package 品牌管理;

import java.sql.*;
import java.util.ArrayList;
import java.util.Scanner;

public class 修改一个品牌 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要修改的品牌id");
        int idQuery = sc.nextInt();

        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql://localhost/db_jdbc_demo22?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
            String user = "root";
            String pass = "000000";
            conn = DriverManager.getConnection(url, user, pass);
            String sql = "update t_brand set brand_name = ?,company_name= ? ,ordered = ?, description = ?,status = ? where id = ?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,"菲利普剃须刀");
            pstmt.setString(2,"菲利普");
            pstmt.setInt(3,30);
            pstmt.setString(4,"刮得更干净");
            pstmt.setInt(5,1);
            pstmt.setInt(6,idQuery);
            int i = pstmt.executeUpdate();
            if (i == 1){
                System.out.println("修改成功");
            }else {
                System.out.println("修改失败");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                pstmt.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
